import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:syria_sports/core/app_export.dart';

import '../../../../data/controllers/subscriptions_controller.dart';
import '../../../../data/models/auth/user.dart';
import '../../../../dialogs/delete_player_confirmation.dart';
import '../../subscriptions_page/models/subscription.dart';

class SubscriptionItemView extends StatelessWidget {
  final Subscription subscription;
  final User user;
  const SubscriptionItemView({super.key, required this.subscription, required this.user});

  @override
  Widget build(BuildContext context) {

    return Slidable(
      enabled: PrefUtils.isGymAdmin(),
      startActionPane: ActionPane(
        motion: const ScrollMotion(),
        children: [
          SlidableAction(
            onPressed: (context){
              showDeleteConfirmation(context, subscription);
            },
            backgroundColor: Colors.transparent,
            foregroundColor: Colors.red,
            icon: Icons.delete,
            label: 'حذف',
          ),
        ],
      ),
      child: Card(
        //color: Colors.white10,
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              //Text(subscription.user!.fullName,style: theme.textTheme.titleMedium),
              Row(
                children: [
                  const Icon(Icons.sports_gymnastics,color: Colors.deepOrange,),
                  const SizedBox(width: 4),
                  Text(subscription.exercise!.name,style: theme.textTheme.titleMedium!.copyWith(color: Colors.deepOrange)),
                ],
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(
                  subscription.gym!.name,
                  overflow: TextOverflow.ellipsis,
                  style: theme.textTheme.displaySmall,
                  maxLines: 2,
                ),
              ),
              Row(
                children: [
                  Text('يبدأ:  ${subscription.startDate.format()}', style: theme.textTheme.displaySmall,),
                  const SizedBox(width: 4),
                  Text('ينتهي: ${subscription.endDate.format()}', style: theme.textTheme.displaySmall),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
  void showDeleteConfirmation(BuildContext context, Subscription subscription) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return DeleteConfirmationDialog(
          playerName: user.fullName,
          titleUser: 'اشتراك اللاعب',
          onConfirm: () {
            SubscriptionsController.deleteById(subscription.subscriptionId??'-1');
          },
        );
      },
    );
  }
}
